682A - Alyona and Numbers - CodeForces Solution


constructive algorithms math number theory *1100

Please click on ads to support us..

Python Code:

def fun(d,ubound):
    c = int(.1*ubound)
    if(d!=0 and ubound%10>=d):
        c+=1
    return c
n,m = map(int,input().split(' '))
count = 0
for a in range(0,10):
    b = 10-a
    if(b==10):b=0
    c1= fun(a,n)
    c2= fun(b,m)
    count += c1*c2
    if(a<=5):
        b2=5-a
    else:
        b2=15-a
    c3=fun(b2,m)
    count+= c1*c3
print(count)

C++ Code:

#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int MOD = 1e9 + 7;
const int INF = LLONG_MAX >> 1;

void solve(int n,int m)
{
    int freq1[5]={0,0,0,0,0};
    int freq2[5]={0,0,0,0,0};
    for(int i=1;i<=n;i++)
    {
        int rem=i%5;
        freq1[rem]++;
    }
    for(int i=1;i<=m;i++)
    {
        int rem=i%5;
        freq2[rem]++;
    }
    int ans=freq1[0]*freq2[0]+freq1[1]*freq2[4]+freq1[2]*freq2[3]+freq1[3]*freq2[2]+freq1[4]*freq2[1];
    cout<<ans<<endl;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin>>n>>m;
    solve(n,m);
}


Comments

Submit
0 Comments
More Questions

1711D - Rain
534A - Exam
1472A - Cards for Friends
315A - Sereja and Bottles
1697C - awoo's Favorite Problem
165A - Supercentral Point
1493A - Anti-knapsack
1493B - Planet Lapituletti
747B - Mammoth's Genome Decoding
1591C - Minimize Distance
1182B - Plus from Picture
1674B - Dictionary
1426C - Increase and Copy
520C - DNA Alignment
767A - Snacktower
1365A - Matrix Game
714B - Filya and Homework
31A - Worms Evolution
1691A - Beat The Odds
433B - Kuriyama Mirai's Stones
892A - Greed
32A - Reconnaissance
1236D - Alice and the Doll
1207B - Square Filling
1676D - X-Sum
1679A - AvtoBus
1549A - Gregor and Cryptography
918C - The Monster
4B - Before an Exam
545B - Equidistant String